package per.hnvcam.searchext.data.dao.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import per.hnvcam.searchext.data.dao.ConditionDAO;
import per.hnvcam.searchext.data.model.Condition;

@Service("ConditionDAO")
@Transactional
public class ConditionDAOImpl extends BaseDAOImpl implements ConditionDAO {

   @SuppressWarnings("rawtypes")
   @Override
   public List listAll() {
      return getHibernateTemplate().find("from Condition");
   }

   @Override
   public Condition findById(long id) {
      @SuppressWarnings("rawtypes")
      List result = getHibernateTemplate().find("from Condition c where c.id = ?", id);
      
      if (result != null && result.size() > 0) {
         return (Condition) result.get(0);
      }
      return null;
   }

   @Override
   public void save(Condition condition) {
      getHibernateTemplate().save(condition);
   }

   @Override
   public void saveOrUpdate(Condition condition) {
      getHibernateTemplate().saveOrUpdate(condition);
   }

   @SuppressWarnings("rawtypes")
   @Override
   public List findAllByRuleId(long id) {
      return getHibernateTemplate().find("from Condition c where c.rule.id = ?", id);
   }
}
